#ifndef CSOURCEMSG_H
#define CSOURCEMSG_H

#include <QStringList>
#include <QSet>
#include <QMap>
#include <QDir>
#include <QTemporaryFile>

#include "netmsg.h"

/**
  The CSourceMsg class is sent from the client to the server when the user has selected the source directory and
  all config options. This message contains all the source files, as well as path information for each source file.
  It is able to reconstruct the source folder structure on the destination machine when required. It also carries a
  config payload, which is used to run the project on the server-side.

  \note This class is a little different to the other messages, since
  */
class CSourceMsg : public CNetMsg
{
public:
	CSourceMsg();
	~CSourceMsg();

	// Add source files to the message. Note that the files will nto be read from disk until the message is serialised,
	// so this method cannot warn you about missing files. Calling this mehtod multiple times will not remove the files
	// previously added, although it will ensure that each file is only added once.
	void addSourceFiles(const QDir &basePath, const QStringList &slFilesToAdd);

	// clear all added files from this message.
	void clearAddedFiles();

	// reconstitute the files on disk, starting at the path specified by basePath. Make sure we have appropriate permissions
	// before calling this!
	void reconstituteFiles(const QDir &basePath);

	// set the config XML that will be sent to the server:
	void setConfigPayload(const QString &strConfig);

	// get the config XMl that will be set to the server:
	QString getConfigPayload() const;

protected:
	void serialiseToStream(QDataStream&) const;
	void serialiseFromStream(QDataStream&);

private:
	QString m_strXMLConfig;
	QDir m_dBaseDir; // base dir - not serialised.

	// on src side we just store filenames in this set (guarantees unique items):
	QSet<QString> m_slFiles;

	// on the dest side we store file data in temporary files:
	//QMap<QString,QTemporaryFile*> m_fileData;
	// store in a single temp file:
	QTemporaryFile *m_pFileData;
};

#endif // CSOURCEMSG_H
